<?php
/**
 * Created by PhpStorm.
 * User: 蒋
 * Date: 2019/5/31
 * Time: 15:00
 */
namespace app\api\controller;
use app\api\model\BindingModel;
use think\Db;
class Binding extends BaseController
{
    public function __construct()
    {
        parent::__construct();
		$this->About = new BindingModel();
	}
    public function AjaxReturn($code,$msg,$data=array())
    {

        $returnData=array(
            "code"=>$code
        );
        if($msg)
        {
            $returnData["message"]=$msg;
        }
        if(!empty($data))
        {
            $returnData["data"]=$data;
        }
        exit(json_encode($returnData));
    }
  	public function index()
    {
        $wechat = Db::name('wechat')->where('uid',$this->uid)->find();
        if(empty($wechat))
        {
            $data['wechat']='0';
        }else{
            $data['wechat']='1';
        }
        $alipay = Db::name('alipay')->where('uid',$this->uid)->find();
        if(empty($alipay))
        {
            $data['alipay']='0';
        }else{
            $data['alipay']='1';
        }
        $bank = Db::name('bank')->where('uid',$this->uid)->find();
        if(empty($bank))
        {
            $data['bank']='0';
        }else{
            $data['bank']='1';
        }
        return $this->AjaxReturn('1','成功',$data);
    }
    public function weibind(){//绑定微信
		$file = request()->post('file');
		
        $name=input('name');
        $uid=$this->uid;
        $number=input('number');
		if($file==''||$uid==''||$name==''||$number==''){
			return $this->AjaxReturn('3','必填项不能为空');
		}
        $list=$this->About->weiadd($name,$uid,$number,$file);
        if($list){
            return $this->AjaxReturn('1','绑定成功');
        }else{
            return $this->AjaxReturn('0','绑定失败');
        }

    }
    public function zhibind(){//绑定支付宝
		$file = request()->post('file');
        $name=input('name');
        $uid=$this->uid;
        $number=input('number');
		if($file==''||$uid==''||$name==''||$number==''){
			return $this->AjaxReturn('3','必填');
		}
        $list=$this->About->zhiadd($name,$uid,$number,$file);
        if($list){
            return $this->AjaxReturn('1','绑定成功');
        }else{
            return $this->AjaxReturn('0','绑定失败');
        }
    }
    public function banklsit(){
        $list=$this->About->banklist();
        if($list){
            return $this->AjaxReturn('1','查询成功',$list);
        }else{
            return $this->AjaxReturn('0','查询失败');
        }
    }
    public function bankbind(){//绑定银行卡
		$uid=$this->uid;
		$open_bank=input('open_bank');
		$name=input('name');
		$number=input('number');
		$branch=input('branch');
		if($uid==''||$name==''||$number==''||$open_bank==''||$branch==''){
			return $this->AjaxReturn('3','必填');
		}
		$list=$this->About->bankbind($uid,$open_bank,$name,$number,$branch);
		if (!empty($list)){
            return $this->AjaxReturn('1','绑定成功');
        }else
            return $this->AjaxReturn('0','绑定失败');
    }
  	public function upload()
    {
        $file = request()->file('file');
        $files=$this->About->upload($file);
        if ($files){
            return $this->AjaxReturn('1','上传成功',$files);
        }else{
            return $this->AjaxReturn('0','上传失败');
        }
    }
}